package com.sumainfor.wx.tenant.controller;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.CompuUtils;
import com.sumainfor.wx.tenant.feign.MarketFeignClient;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  合租人信息
 * <p>
 *
 * @author: Mr.Wang
 * @create: 2019-04-18 15:26
 **/
@Controller
@RequestMapping("/tenantInformation")
public class TenantInformationController {

    @Autowired
    MarketFeignClient marketFeignClient;

    /**
    * <p>
    * 根据租客id查询合租人
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @ResponseBody
    @PostMapping("/getTenantInformation")
    public JsonResult getTenantInformation(@RequestBody Map<String,Object> params){
        JsonResult result = new JsonResult();
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"TenId"})){
            return  result.putFailed("租客编号不能为空!");
        }
        return marketFeignClient.getTenantInformation(params);

    }

    /**
    * <p>
    * 新增合租人1
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @ResponseBody
    @PostMapping("/insertTenantInformation")
    public JsonResult insertTenantInformation(@RequestBody Map<String,Object> params){
        JsonResult result = new JsonResult();
        System.out.println("params"+params);
        String b = "10";
        System.out.println("Area"+MapUtils.getDoubleValue(params,"Area"));
      if(Math.floor(MapUtils.getDoubleValue(params,"Area"))<10){
          return  result.putFailed("合租人数已满，无法新增合租人!");
      }

        List<Map<String,Object>> para = (List<Map<String,Object>>)params.get("parList");
        if (para!=null&&para.size()>0){
           return  result.putFailed("合租人数已满，无法新增合租人!");
        }
        return result.putSuccess("可以添加合租人!");
         //return marketFeignClient.insertTenantInformation(params);
    }

    /**
     * <p>
     * 新增合租人1
     * </p>
     *
     * @author: zhoucong
     * @since:
     */
    @ResponseBody
    @PostMapping("/insertTenantInformationOne")
    public JsonResult insertTenantInformationOne(@RequestBody Map<String,Object> params){
        return marketFeignClient.insertTenantInformation(params);
    }

    /**
    * <p>
    * 删除合租人
    * </p>
    *
    * @author: zhoucong
    * @since:
    */
    @ResponseBody
    @PostMapping("/deleteTenantInformation")
    public JsonResult deleteTenantInformation(@RequestBody Map<String,Object> params){
        return marketFeignClient.deleteTenantInformation(params);
    }


}
